/**
 * 获取数据库中的覆盖物
 *
 */
loadOverlays();
/**
 * 加载数据库中的覆盖物
 */
function loadOverlays() {
    $.ajax({
        url: '/baiDuMap/getmap',
        method: "post",
        success: function (data) {
            data = data.data;
            console.log('data:', data);
            for (var d in data) {
                console.log('dots:', data[d].dots);
                add_overlay(data[d].dots, data[d].fillColor);
            }
        },
        error: function () {
            // layer.msg("添加失败");
            layer.msg("ajax执行失败");
        }
    });
}
window.dbOverlay = [];
/**
 * 添加覆盖物
 * @param dots:覆盖物的点
 * @param dots:覆盖物的填充色
 */
function add_overlay(dots, color) {
    //增加多边形
    var overDots = setOverDots(dots);
    console.log('overDots',overDots)
    var polygon = new BMap.Polygon(overDots, {strokeColor: color, fillColor: color, strokeWeight: 3,
        strokeOpacity: 0.8, fillOpacity: 0.6});  //创建多边形
    map.addOverlay(polygon);
    window.dbOverlay.push(polygon);
}

/**
 * 设置多变形覆盖物的点
 */
function setOverDots(dots) {
    var overDots = [];
    for (var d in dots) {
        overDots.push(new BMap.Point(dots[d].lng, dots[d].lat))
    }
    return overDots;
}